package com.base.myproject.client.HR.Self;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.LasyObejct;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.ui.BaseFormPanel;
import com.base.myproject.client.ui.BaseGrid;
import com.base.myproject.client.ui.BaseGridPanel;
import com.base.myproject.client.ui.celleditor.BaseComboBoxForm;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.NumberFormat;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class SelfBcode_salary extends LayoutContainer implements LasyObejct{
	BaseStore<BusiObject> mainstore = null;

	String bcode_HR="";
	String w_date="";//入职日期
	
	public SelfBcode_salary(BaseStore<BusiObject> mainstore) {
		this.mainstore = mainstore;
		init();
		//this.setStyleAttribute("background-color", "#DFE8F6");
	}

	void init() {
		initwidget();
		
	}
	Widget initwidget() {
		FieldSet fs1 = new FieldSet();
		//fs1.setHeight(125);
		fs1.add(createForm());
		//fs1.setStyleName("firldset_css1");
	//	fs1.add(createBcode_Employment_Form());
		fs1.setHeading("薪金信息");
		FieldSet fs2 = new FieldSet();
		fs2.add(creatAllowanceeGrid());
		fs2.setHeading("薪金记录");
		
		VerticalPanel v = new VerticalPanel();
		v.setSpacing(2);
		v.add(fs1);
		v.add(fs2);
		//v.setHeight(420);
		this.add(v);
		return null;
	}
	/********/
	BaseFormPanel createForm() {
		BaseFormPanel form = new BaseFormPanel(mainstore);
		form.setBodyBorder(false);
		form.setPadding(6);
		form.setStyleName("form_css2");
		TableLayout tl = new TableLayout(8);

		TableData td = new TableData();
		td.setRowspan(1);
		td.setHorizontalAlign(HorizontalAlignment.LEFT);
		td.setVerticalAlign(VerticalAlignment.TOP);
		td.setPadding(2);
		
		
		form.add(new Label("薪金:"), td);
		NumberField C_num31 = new NumberField();
		C_num31.setName("basesalary");
		C_num31.setReadOnly(true);
		form.add(C_num31, td);
		
		form.add(new Label("银行:"), td);
		TextField<String> C_num22 = new TextField<String>();
		C_num22.setReadOnly(true);
		C_num22.setName("hr_bankno");
		form.add(C_num22, td);
		
		form.add(new Label("银行账户:"), td);
		TextField<String> C_num23 = new TextField<String>();
		C_num23.setReadOnly(true);
		C_num23.setName("hr_bankcard");
		form.add(C_num23, td);
		
		form.add(new Label("社保编号:"), td);
		TextField<String> C_num19 = new TextField<String>();
		C_num19.setReadOnly(true);
		C_num19.setName("hr_social_no");
		form.add(C_num19, td);
		
		form.setLayout(tl);
		form.setHeaderVisible(false);
		form.inited(135);
		return form;
	}

	/**********************/
	BaseStore<BusiObject> bcode_Allowance_store = null;

	public BaseStore<BusiObject> get_bcode_Allowance_Store() {
		if (bcode_Allowance_store == null) {
			create_bcode_Allowance_Store();
		}
		return bcode_Allowance_store;
	}

	BaseStore<BusiObject> create_bcode_Allowance_Store() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("bcode");
		type.getField("bcode").setType(String.class);
		type.addField("no_");
		type.getField("no_").setType(String.class);
		type.addField("desc_cn");
		type.getField("desc_cn").setType(String.class);
		type.addField("startdate");
		type.getField("startdate").setType(Date.class);
		type.addField("enddate");
		type.getField("enddate").setType(Date.class);
		type.addField("amount");
		type.getField("amount").setType(Double.class);
		type.addField("vprepare");
		type.getField("vprepare").setType(String.class);
		type.addField("modifydate");
		type.getField("modifydate").setType(String.class);
		type.addField("createdate");
		type.getField("createdate").setType(Date.class);
		StoreInfo info = new StoreInfo();
		info.setTablename("bcode_Allowance");
		info.setKeyname(new String[] { "icode" });
		info.setSql("select * from bcode_Allowance where bcode ='{bcode}' and status =0");
		info.setParent(mainstore);// 关联主表
		info.setLinkparentcolumns(new String[] { "bcode" }); // 关联主表字段
		info.setLinkparent_chile_columns(new String[] { "bcode" });// 关联主表字段
		bcode_Allowance_store = new BaseStore<BusiObject>(type, info);
		return bcode_Allowance_store;
	}
	
	BaseGrid bcode_Allowance_grid = null;
	NumberField amount ;
	BaseGrid creatAllowanceeGrid() {
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();

		ColumnConfig C3 = new ColumnConfig("no_", "薪金编码", 100);
		BaseComboBoxForm<BaseModelData> bsb2 = new BaseComboBoxForm<BaseModelData>("code","desc_cn","hr_Salary_Item","",true);//new BaseComboBoxForm(CodeNameMapFactory.loadBcode_801());
		C3.setRenderer(bsb2);
		columns.add(C3);
		
		ColumnConfig C5 = new ColumnConfig("startdate", "生效开始日期", 120);
		DateField dateField5 = new DateField();  
		dateField5.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));  
		C5.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		columns.add(C5);
		
		ColumnConfig C6 = new ColumnConfig("enddate", "截止日期", 120);
		DateField dateField6 = new DateField();  
		dateField6.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));  
		C6.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		columns.add(C6);
		
		ColumnConfig C7 = new ColumnConfig("amount", "金额", 80);
		C7.setNumberFormat(NumberFormat.getCurrencyFormat());  
		amount = new NumberField();
		columns.add(C7);
		
		ColumnModel cm = new ColumnModel(columns);
		bcode_Allowance_grid = new BaseGrid(get_bcode_Allowance_Store(), cm, false, false);
		bcode_Allowance_grid.setHeight(200);
		return bcode_Allowance_grid;
	}

	@Override
	public boolean isopen() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean open() {
		// TODO Auto-generated method stub
		return false;
	}
}
